package gist;

import java.text.NumberFormat;

/**
 * describe:格式化数值
 * author:gss
 *
 * @note：
 * @knowledge: 使用NumberFormat
 * create_time:2016/1/30 16:25
 */
public class NumberFormatApp {

    public void getNumberFormatMethod(double d) {
        NumberFormat numberFormat = NumberFormat.getCurrencyInstance();//返回货币实例
        String value = numberFormat.format(d);
        System.out.println("格式化为货币的效果：" + value);
        numberFormat = NumberFormat.getIntegerInstance();//返回整数格式
        value = numberFormat.format(d);
        System.out.println("格式化为整数的效果：" + value);
        numberFormat = NumberFormat.getPercentInstance();//返回百分数格式
        value = numberFormat.format(d);
        System.out.println("格式化为百分数的效果：" + value);
    }

    public static void main(String[] args) {
        NumberFormatApp numberFormatApp=new NumberFormatApp();
        numberFormatApp.getNumberFormatMethod(123.456789);
    }
}
